package PAT;

import java.util.Scanner;

public class PAT1024 {
    public static long ans = -1;
    public static int tk = -1;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextInt();
        int k = scanner.nextInt();
        tk = k;
        long p = subFun(n,k);
        System.out.println(p);
        System.out.print(ans);
    }

    private static long subFun(Long n, Integer k) {
        if(k==0) {
            ans = tk;
            return n;
        }
        StringBuilder stringBuilder = new StringBuilder(n.toString());
        StringBuilder reverse = stringBuilder.reverse();
        long p = Long.parseLong(reverse.toString()) + n;
        reverse = new StringBuilder(Long.toString(p));
        String s0 = reverse.toString();
        String s = reverse.reverse().toString();
        if(s.equals(s0)){
            ans = tk - k+ 1;
            return p;
        }else{
            return subFun(p,k-1);
        }
    }
}
